package com.cskaoyan.controller.stage;

import com.cskaoyan.model.Comment;
import com.cskaoyan.model.bo.WxCommentBO;
import com.cskaoyan.model.vo.*;
import com.cskaoyan.service.UserService;
import com.cskaoyan.service.WxCommentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: WxCommentController
 * @Description: Comment控制层
 * @Author:YPS
 * @Date: 2022/5/9 20:53
 * @Version: 1.0
 **/
@RestController
@RequestMapping("wx/comment")
public class WxCommentController {
    @Autowired
    WxCommentService commentService;
    @Autowired
    UserService userService;

    @RequestMapping("list")
    public BaseRespVO<DataVO<WxCommentDetailsVO>> getCommentList(WxCommentBO wxCommentBO) {
        DataVO<WxCommentDetailsVO> commentListVODataVO = commentService.getCommentList(wxCommentBO);
        return BaseRespVO.ok(commentListVODataVO);
    }

    @RequestMapping("count")
    public BaseRespVO<WxCommentCountVO> getCommentCount(Integer valueId, Integer type) {
        WxCommentCountVO commentCountVO = commentService.getCommentCount(valueId, type);
        return BaseRespVO.ok(commentCountVO);
    }

    @RequestMapping("post")
    public BaseRespVO<Comment> postComment(@RequestBody Comment comment) {
        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId = userService.getUserIdByUsername(username);
        comment.setUserId(userId);
        Comment commentDataVO = commentService.postComment(comment);
        return BaseRespVO.ok(commentDataVO);
    }
}
